<!--app版本管理信息 -->
<template>
  <div class="table">
    <!-- 列表 -->
    <SearchTable :selectPlatformType="selectPlatformType" v-model:formStatus="formStatus" @handleViewEdit="handleViewEdit" ref="searchTableRef" />
    <!-- 弹窗表单 -->
    <FormDialog :selectPlatformType="selectPlatformType" v-model:formStatus="formStatus" v-model:form="form" @handleSuccess="handleSuccess" />
  </div>
</template>

<script setup lang="ts" name="softwareUpgrade">
import SearchTable from "@/components/configInfo/softwareUpgrade/SearchTable.vue";
import FormDialog from "@/components/configInfo/softwareUpgrade/FormDialog.vue";
import type { ViewMode, ViewModeFilter } from "@/types/common";
import { useDictData } from "@/hooks/network/useDictData";
import type { IDictData } from "@/types/dict";
import type { IAppVersionDTO, IAppVersionVO } from "@/types/appVersion";
const formStatus = ref<ViewMode>("none");
/* 组织 */
const selectPlatformType = ref<Array<IDictData>>([]);

/* 表格子组件的引用 */
const searchTableRef = useTemplateRef("searchTableRef");

/* 表单数据 */
const form = reactive<IAppVersionDTO>({
  id: 0,
  type: "",
  version_code: "",
  descriptions: []
});

/* 点击编辑按钮 */
function handleViewEdit(row: IAppVersionVO, code: ViewModeFilter) {
  formStatus.value = code;
  /* nextTick 解决重置该表单项 初始化的数据问题 */
  nextTick(() => {
    form.id = row.id;
    form.type = row.type;
    form.version_code = row.version_code;
    form.descriptions = JSON.parse(row.descriptions);
  });
}
/* 成功保存或者编辑的回调 */
function handleSuccess() {
  searchTableRef.value?.getTableInfo();
}
let { getDictData } = useDictData();
getDictData("APP_VERSION_TYPE", selectPlatformType);
</script>

<style lang="scss" scoped></style>
